package com.wl2o2o.writtenview.acm360;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * @Author <a href="https://github.com/wl2o2o">程序员CSGUIDER</a>
 * @From <a href="https://wl2o2o.github.io">CSGUIDER博客</a>
 * @CreateTime 2024/3/9
 */

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] foods = new int[n];
        for (int i = 0; i < n; i++) {
            foods[i] = scanner.nextInt();
        }
        scanner.close();

        int minMix = findMinMix(foods);
        System.out.println(minMix);



    }

    private static int findMinMix(int[] foods) {
        int minMix = 0;
        Set<Integer> uniqueFoods = new HashSet<>();
        for (int i = 0; i < foods.length; i++) {
            if (uniqueFoods.contains(foods[i])) {
                int newFood = foods[i] + 1;
                while (uniqueFoods.contains(newFood)){
                    newFood++;
                }
                uniqueFoods.add(newFood);
                minMix++;

            } else {
                uniqueFoods.add(foods[i]);
            }
        }
        return minMix;
    }
}
